package kr.hkit.androidcomplete02.ch16;

import java.util.Calendar;

import kr.hkit.androidcomplete02.R;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.os.Bundle;
import android.util.Log;
import android.view.View;

public class ShowDialogEx extends Activity {
	final static int SAMPLE_DLG = 0;
	final static int QUESTION_DLG = 1;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.ch16_showdialog);
	}
	
	@SuppressWarnings("deprecation")
	public void mOnClick(View v){
		switch(v.getId()){
		
		case R.id.call_1:
			showDialog(SAMPLE_DLG);
			break;
			
		case R.id.call_2:
			showDialog(QUESTION_DLG);
			break;
		}
	}

	// 다이얼로그를 생성한 것을 Return만 한다.
	@Override
	protected Dialog onCreateDialog(int id) {
		Log.d("ShowDialogEx", "onCreateDialog" + (id == 0 ? SAMPLE_DLG : QUESTION_DLG) );
		switch(id){
		
		case SAMPLE_DLG:
			return new AlertDialog.Builder(ShowDialogEx.this)
			.setTitle("알립니다")
			.setMessage("대화상자를 열었습니다.")
			.setIcon(R.drawable.androboy)
			.setPositiveButton("닫기", null)
			.create();
			
		case QUESTION_DLG:
			return new AlertDialog.Builder(ShowDialogEx.this)
			.setTitle("질문")
			.setMessage("밥 먹었어요?")
			.setPositiveButton("먹었다", null)
			.setNegativeButton("굶었다", null)
			.create();
		}
		return null;
	}

	@Override
	protected void onPrepareDialog(int id, Dialog dialog) {
		
		Log.d("ShowDialogEx", "onPrepareDialog" + (id == 0 ? SAMPLE_DLG : QUESTION_DLG) );
		switch(id){
		
		case SAMPLE_DLG:
			break;
			
		case QUESTION_DLG:
			Calendar calendar = Calendar.getInstance();
			String stime = String.format("%d시 %d분 %d초", calendar.get(Calendar.HOUR_OF_DAY), calendar.get(Calendar.MINUTE), calendar.get(Calendar.SECOND));
			dialog.setTitle(stime);
				break;
		}
	}
	
	
}
